home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / docs / misc / ConcNews.lha / news / amiga.programming / comp.sys.amiga.programmer_10336_000066.msg < prev    next >
Encoding:
Internet Message Format  |  1994-11-27  |  3.0 KB

  1. Path: dd.chalmers.se!news.chalmers.se!sunic!trane.uninett.no!nac.no!eunet.no!nuug!EU.net!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!ames!olivea!charnel.ecst.csuchico.edu!yeshua.marcam.com!MathWorks.Com!news.duke.edu!eff!news.umbc.edu!haven.umd.edu!cville-srv.wam.umd.edu!walrus
  2. From: walrus@wam.umd.edu (Udo K Schuermann)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: How the hell does multitasking work?
  5. Date: 5 May 1994 21:00:40 GMT
  6. Organization: University of Maryland, College Park
  7. Lines: 43
  8. Message-ID: <2qbmpo$anm@cville-srv.wam.umd.edu>
  9. References: <cmanCpBKq0.Lw2@netcom.com>
  10. NNTP-Posting-Host: rac1.wam.umd.edu
  11.  
  12. In article <cmanCpBKq0.Lw2@netcom.com>, Mike Austin <cman@netcom.com> wrote:
  13. > How does exec 'let' on execute it's instructuins for a while then 'let' the
  14. > other process have some time?  To execute an instruction don't you have to
  15. > jump to that location?  If you did that you would 'become' that processs
  16. > and not end until you're done...
  17.  
  18. How Preemptive Multitasking Works:
  19.  
  20. 1. A part of the Operating System (Exec on the Amiga) maintains a list of
  21.    all tasks/processes that are waiting for a CPU.  This is the Ready
  22.    Queue.  It also has a list of all processes currently running, this is
  23.    the Run Queue.  One a single CPU system, there may be many processes in
  24.    the Ready, but only one in the Run Queue.
  25.  
  26. 2. Now, the OS (Exec) uses a timer on the Running Task (Run Queue) and when
  27.    the task's time is up, it saves the so-called CPU State (PC, SP, SR, all
  28.    the registers) in the TCB (Task Control Block), takes it out of the Run
  29.    Queue, and moves the next TCB out of the Ready into the Run Queue.
  30.       The PC, SP, SR, and registers are loaded from the new task's TCB and
  31.    processing continues where it left off the last time that this task was
  32.    suspended.
  33.       This is the task-swapping process and represents the sole overhead in
  34.    Exec (AFAIK.)  In fact, when a task's time is up (i.e. its quantum has
  35.    expired) it is necessary to task-swap ONLY IF ANOTHER TASK IS IN THE
  36.    WAIT QUEUE.  If the Wait Queue is empty, then the task is NOT swapped
  37.    and does NOT lose the CPU.  This is why a system with twenty running
  38.    programs, all waiting for an event, consume NO CPU time and can let
  39.    another task (even at lower priority) run at FULL SPEED.
  40.  
  41. And there you have it.  Things get trickier when you deal with prioritized
  42. queues (i.e. multiple Ready Queues, one for each priority level) and when
  43. you use semaphores and suspended tasks (tasks waiting for signals and
  44. events (such as Wait()ing for a mouse click, keypress or disk insert) are
  45. stored in a Wait Queue unique to each possible event, semaphore, signal,
  46. etc.
  47.  
  48. Complications abound, but that should give everyone an idea what's
  49. happening inside Exec and most other such setups.
  50.  
  51. We now return you to the frightened ramblings of people without nerve.
  52.  
  53.  ._.  Udo Schuermann                  Someone kick the "fat lady"
  54.  ( )  walrus@wam.umd.edu              before she starts to sing!
  55.